package com.dkd.manage.controller;

import com.dkd.common.core.domain.AjaxResult;
import com.dkd.manage.domain.TbSales;
import com.dkd.manage.service.TbSalesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/dashboard")
public class DashboardController {

    @Autowired
    private TbSalesService tbSalesService;

    @GetMapping("/sales-distribution")
    public AjaxResult getSalesDistribution() {
        List<TbSales> list = tbSalesService.getSalesList();
        // 转换为前端需要的格式
        List<Map<String, Object>> result = list.stream()
            .map(s -> {
                Map<String, Object> map = new HashMap<>();
                map.put("name", s.getArea());
                map.put("value", s.getAmount());
                return map;
            })
            .collect(Collectors.toList());
        return AjaxResult.success(result);
    }
}
